//
//  SLBaseRequest.h
//  shunlianPower2
//
//  Created by 童玉龙 on 2018/12/8.
//  Copyright © 2018 顺联网络. All rights reserved.
//

#import <YTKNetwork/YTKNetwork.h>
NS_ASSUME_NONNULL_BEGIN

@class SLBaseRequest;

/**
 网络请求返回callBack
 成功时返回的经过处理的数据,即经过初步解析过的数据,可直接使用.

 @param request 请求
 @param data 成功时返回的经过处理的数据,失败时为nil,可用来判断数据是否返回成功,也可用responseResult判断
 */
typedef void(^SLRequestCallBack)(SLBaseRequest * _Nullable request,id _Nullable data);

@protocol SLRequestDelegate <YTKRequestDelegate>

/// 网络请求成功后收到的回调,data是网络返回的数据(可以是经过统一处理后的数据)
/// @param request 当前请求
/// @param data 数据
- (void)request:(SLBaseRequest *_Nullable)request data:(id _Nullable )data;

@end

@interface SLBaseRequest : YTKBaseRequest

@property (nonatomic, strong) NSString *path;
@property (nonatomic, strong) NSDictionary *parameters;
/** <#注释#>*/
@property (nonatomic, assign) YTKRequestSerializerType requestSerializerType;
/** <#注释#>*/
@property (nonatomic, assign) YTKResponseSerializerType responseSerializerType;
/** <#注释#>*/
@property (nonatomic, strong) NSDictionary<NSString *,NSString *> * requestHeader;

/// 从responseJSONObject初步解析过之后的对象,解析类请遵循<SLNetworkInterceptors>协议.
@property (nonatomic, strong, readwrite, nullable) id responseParsedObject;

@property (nonatomic, assign) YTKRequestMethod method;

@property (nonatomic, assign) NSInteger currentPage;
@property (nonatomic, assign) NSInteger totalPage;

/// 类方法发起Get网络请求,支持delegate回调
/// @param delegate 代理,可为nil
/// @param path 请求路径
/// @param parameters 参数,可为nil
+ (SLBaseRequest *)getRequestWithDelegate:(nullable id<SLRequestDelegate>)delegate
                                     path:(NSString *)path
                               parameters:(nullable NSDictionary *)parameters;

/// 类方法发起Gett网络请求,支持block回调
/// @param path 请求路径
/// @param parameters 参数,可为nil
/// @param callBack block回调,可为nil
+ (SLBaseRequest *)getRequestWithPath:(NSString *)path
                           parameters:(nullable NSDictionary *)parameters
                             callBack:(nullable SLRequestCallBack)callBack;

/// 类方法发起Post网络请求,支持delegate回调
/// @param delegate 代理,可为nil
/// @param path 请求路径
/// @param parameters 参数,可为nil
+ (SLBaseRequest *)postRequestWithDelegate:(nullable id<SLRequestDelegate>)delegate
                                      path:(NSString *)path
                                parameters:(nullable NSDictionary *)parameters;

/// 类方法发起Post网络请求,支持block回调
/// @param path 请求路径
/// @param parameters 参数,可为nil
/// @param callBack block回调,可为nil
+ (SLBaseRequest *)postRequestWithPath:(NSString *)path
                            parameters:(nullable NSDictionary *)parameters
                              callBack:(nullable SLRequestCallBack)callBack;


/// 类方法发起网络请求,同时支持block回调和delegate回调返回数据
/// @param delegate 代理,可为nil
/// @param method 请求方法
/// @param path 请求路径
/// @param parameters 参数,可为nil
/// @param callBack block回调,可为nil
+ (SLBaseRequest *)requestWithDelegate:(nullable id <SLRequestDelegate>)delegate
                                method:(YTKRequestMethod)method
                                  path:(NSString *)path
                            parameters:(nullable NSDictionary *)parameters
                              callBack:(nullable SLRequestCallBack)callBack;

@end

NS_ASSUME_NONNULL_END
